#ifndef __VLOG_MUTEXT_H__
#define __VLOG_MUTEXT_H__

#include <mutex>
#include <thread>
class CASMutex
{
    public:
    CASMutex() = default;

    void lock()
    {
        while (m_flag.test_and_set(std::memory_order_acquire))
        {
            std::this_thread::yield();
        }
    }

    void unlock()
    {
        m_flag.clear(std::memory_order_release);
    }

    bool try_lock()
    {
        return !m_flag.test_and_set(std::memory_order_acquire);
    }

    private:
    CASMutex(const CASMutex&) = delete;
    CASMutex& operator=(const CASMutex&) = delete;

    CASMutex(CASMutex&&) = delete;
    CASMutex& operator=(const CASMutex&&) = delete;

    std::atomic_flag m_flag{ATOMIC_FLAG_INIT};
};

#endif